package com.fho4565.core;


import com.fho4565.gui.CustomGUI;

import java.io.Serial;
import java.util.HashSet;

public class DisplayList extends HashSet<DisplayObject> implements Cloneable {
    @Serial
    private static final long serialVersionUID = -471133030789732078L;

    public DisplayList() {
        super();
    }

    public void renderAll(CustomGUI gui){
        for(DisplayObject displayObject : this){
            displayObject.render(gui);
        }
    }
    public DisplayObject getByName(String name){
        return this.stream().filter(displayObject -> displayObject.getName().equals(name)).findFirst().orElse(null);
    }
    public void remove(String name){
        this.removeIf(displayObject -> displayObject.getName().equals(name));
    }
    public boolean contains(String name){
        return this.stream().anyMatch(displayObject -> displayObject.getName().equals(name));
    }
    @Override
    public Object clone() {
        DisplayList result;
        result = (DisplayList)super.clone();
        result.clear();
        result.addAll(this);
        return result;
    }
}
